package com.dommy.tab.util;

import com.dommy.tab.pojo.WaterVO;

import java.util.ArrayList;
import java.util.List;

/**
 * waterUtil
 * Created by 光头 on 2020/7/4.
 */

public class WaterUtil {
    public static ArrayList<ArrayList<WaterVO>> WATER_LIST = new ArrayList<>();
    public static  ArrayList<WaterVO> WATER_DAY = new ArrayList<>();
    public static boolean FLAG = true;
    public static void INIT() {
        FLAG = true;
        final Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                    Updata();
            }
        });
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (WaterUtil.FLAG){
                    thread.run();
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();
    }

    public static void  Updata(){
        WaterUtil.WATER_LIST = new ArrayList<>();
        WaterUtil.WATER_DAY = new ArrayList<>();
        MyHttpObject myHttpObject = new MyHttpObject();
//        System.out.println("url:          "+MyUrlUtil.SELECT_DAYS+UserUtil.USER_ID);
        myHttpObject.setList(MyUrlUtil.SELECT_DAYS+UserUtil.USER_ID,WaterVO.class);
        WaterUtil.WATER_DAY = myHttpObject.getList();
        WaterUtil.WATER_LIST.add(WATER_DAY);
        myHttpObject.setList(MyUrlUtil.SELECT_MONTHS+UserUtil.USER_ID,WaterVO.class);
        WaterUtil.WATER_LIST.add(myHttpObject.getList());
        myHttpObject.setList(MyUrlUtil.SELECT_YEARS+UserUtil.USER_ID,WaterVO.class);
        WaterUtil.WATER_LIST.add(myHttpObject.getList());
    }


    public static double[] getDaysWater(){
        while(WATER_DAY == null || WATER_DAY.size()==0){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        double[] ints = new double[WATER_DAY.size()];
        for(int i =0; i< ints.length ;i++){
            ints[i] = WATER_DAY.get(i).getMonthWater();
        }
        return ints;
    }
}
